<!--
 * @Descripttion: 
 * @version: 
 * @Author: 淏
 * @Date: 2023-11-26 17:50:05
 * @LastEditors: 淏
 * @LastEditTime: 2024-05-03 12:10:08
-->
<template>
  <el-select
    ref="selectColumnType"
    v-model="value"
    placeholder="请选择数据集名称"
    size="mini"
    :popper-append-to-body="false"
  >
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.name"
      :value="item.id"
    ></el-option>
  </el-select>
</template>

<script>
  import { queryByType_import } from '@/api/index.js'
  export default {
    // 组件名称
    name: 'selectImport',
    // 组件参数 接收来自父组件的数据
    props: {
      type: {
        type: String,
        required: true,
      },
      importId: {
        type: Number,
        default: -1,
      },
    },
    // 局部注册的组件
    components: {},
    // 组件状态值
    data() {
      return {
        options: [],
        value: '',
        chooseData: {
          id: 0,
          name: '',
          type: '',
          createTime: '',
        },
      }
    },
    // 计算属性
    computed: {},
    // 侦听器
    watch: {
      value(value) {
        this.findData(value)
      },
    },
    // 组件方法
    methods: {
      getData(row) {
        var qs = require('qs')
        let type
        if (row) {
          type = row
        } else {
          type = this.type
        }
        var data = qs.stringify({
          type: type,
        })
        queryByType_import(data).then((res) => {
          this.options = res.data
          if (!this.importId || this.importId == null) {
            this.getDefaultValues()
          }
        })
      },
      findData(row) {
        this.chooseData = this.options.find((item) => {
          return item.id == row
        })
        this.$emit('getImport', this.chooseData)
      },
      getDefaultValues() {
        let defaultValue = this.options[0]
        this.$emit('getDefaultValue', defaultValue)
      },
    },
    created() {},
    mounted() {
      this.getData()
      this.value = this.importId
    },
  }
</script>

<style scoped></style>
